package cs5226.model;

import java.sql.Timestamp;
import java.util.List;

import cs5226.util.StringUtil;

public class RedoAllocationHitStatistics extends Statistics {
	private double allocationHitRatio;
	
	@Override
	public String getText() {
		return StringUtil.formatDouble(allocationHitRatio);
	}

	public double getAllocationHitRatio() {
		return allocationHitRatio;
	}

	public void setAllocationHitRatio(double cacheHitRatio) {
		this.allocationHitRatio = cacheHitRatio;
	}
	
	public RedoAllocationHitStatistics(Timestamp t, double cacheHitRatio) {
		super();
		super.setTs(t);
		this.allocationHitRatio = cacheHitRatio;
	}
	
	@Override
	public Statistics aggregate(List<Statistics> statList) {
		if (statList == null || statList.size() == 0) return null;
		
		double agrVal = 0;
		for (int i=0; i<statList.size(); i++) {
			if (statList.get(i) instanceof RedoAllocationHitStatistics) {
				agrVal += ((RedoAllocationHitStatistics)statList.get(i)).getAllocationHitRatio(); 
			}
		}
		return new RedoAllocationHitStatistics (statList.get(0).getTs(), agrVal/statList.size());
	}

}
